set.seed(12345) x <- rnorm(400,550,100) x <- round(x,0) cutpoint <- 650 y <- .98*x + (ifelse(x>cutpoint,30,0)) + round(rnorm(400,0,30),0) y <- round(y,0) x.1 <- subset(x, x<=cutpoint) y.1 <- subset(y, x<=cutpoint) T <- ifelse(x>cutpoint,1,0) fit.1 <- lm(y.1~x.1) x.2 <- subset(x, x >cutpoint) y.2 <- subset(y, x>cutpoint) fit.2 <- lm(y.2~x.2) plot(x.1,y.1,xlim=c(150,900),ylim=c(150,800),pch=1,xlab="Assignment Variable Scores",ylab="Posttest Scores") points(x.2,y.2,pch=16) curve(coef(fit.1)[1] + coef(fit.1)[2]*x,xlim=c(150,cutpoint),col="red",add=TRUE) curve(coef(fit.2)[1] + coef(fit.2)[2]*x,xlim=c(cutpoint,800),col="blue",add=TRUE) abline(v=cutpoint) PSAT <- data.frame(x,y,T) write.table(PSAT,"PSAT.txt",row.names=F)